import request from '../plugins/axios'

// --------------------------分类 START

// 创建分类 批量创建
export const CreateCategory = (params) => {
  return request({
    url: 'category',
    method: 'post',
    data: params
  })
}

// 查询所有分类
export const GetAllCategory = () => {
  return request({
    url: 'category',
    method: 'get'
  })
}

// 获取每个分类下文章数
export const GetArticleCountUnderCategory = () => {
  return request({
    url: 'article/category/count',
    method: 'get'
  })
}

export const UpdateOneCategory = (params) => {
  return request({
    url: 'category/' + params._id,
    method: 'post',
    data: params
  })
}

export const DeleteCategory = (params) => {
  return request({
    url: 'category',
    method: 'delete',
    data: params
  })
}
// --------------------------分类 END

// --------------------------文章 START

// 创建文章 批量创建
export const CreateArticle = (params) => {
  return request({
    url: 'article',
    method: 'post',
    data: params
  })
}

// 文章数量 草稿 已发布
export const GetArticleCount = (params) => {
  return request({
    url: 'article/count',
    method: 'get',
    params
  })
}

// 条件查询文章 带分页
export const GetArticle = (params) => {
  return request({
    url: 'article',
    method: 'get',
    params
  })
}

export const GetTopArticle = () => {
  return request({
    url: 'article/top',
    method: 'get'
  })
}

export const UpdateOneArticle = (params) => {
  return request({
    url: 'article/' + params._id,
    method: 'post',
    data: params
  })
}

export const DeleteArticle = (params) => {
  return request({
    url: 'article',
    method: 'delete',
    data: params
  })
}

// --------------------------文章 END

// --------------------------用户 START
// 查询用户名重复
export const CheckUsernameRepeat = (params) => {
  return request({
    url: 'user/repeat',
    method: 'post',
    data: params
  })
}

// 注册
export const SignUp = (params) => {
  return request({
    url: 'register',
    method: 'post',
    data: params
  })
}

// 登录
export const SignIn = (params) => {
  return request({
    url: 'login',
    method: 'post',
    data: params
  })
}
// --------------------------用户 END

export const GetVisitCount = (params) => {
  return request({
    url: 'log/visit/count',
    method: 'get',
    params
  })
}

// 上传文件
export const uploadImage = (params) => {
  return request({
    url: 'file',
    method: 'post',
    data: params
  })
}

export const GetAddress = () => {
  return request({
    url: 'http://ip-api.com/json/?fields=520191&lang=zh-CN',
    method: 'get'
  })
}

export const GetWeather = (ip) => {
  return request({
    url: 'https://tianqiapi.com/api?version=v6&appid=84187797&appsecret=OoVjho72&vue=1&ip=' + ip,
    method: 'get'
  })
}

// Friend S
export const GetAllFriend = () => {
  return request({
    url: 'friend',
    method: 'get',
  })
}

export const MakeFriend = (friend) => {
  return request({
    url: 'friend',
    method: 'post',
    data: friend
  })
}

export const ModifyFriend = (friend) => {
  return request({
    url: 'friend/' + friend._id,
    method: 'post',
    data: friend
  })
}

export const RemoveFriend = (friend) => {
  return request({
    url: 'friend',
    method: 'delete',
    data: friend
  })
}
// Friend E
